//
//  HMFooterView.swift
//  HMWeiBo
//
//  Created by Apple on 16/8/1.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class HMFooterView: UIView {

    var footerViewModel: HMHomeCellViewModel? {
        
        didSet{
            
            retweetButton.setTitle(footerViewModel?.retweet_String, forState: UIControlState.Normal)
            
        }
        
    }
    
    // 第一步: 重写父类的构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 第二步: 定义一个添加子类和设置子类控件约束的方法
    private func setupUI(){
        
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(goodButton)
        
        // 设置约束 -- 最主要的就是 等宽等高
        retweetButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(commentButton.snp_width)
            
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetButton.snp_right)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(goodButton.snp_left)
            make.bottom.equalTo(self.snp_bottom)
        }
        
        goodButton.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(commentButton.snp_width)
            
        }
        
    }
    
    //第三步: 懒加载控件
    //MARK:-- 懒加载控件
    
    ///转发
    private lazy var retweetButton: UIButton = {
    
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        
        button.setTitle("转发", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        
        // 注意: 修改按钮的字体的话 titleLabel
        button.titleLabel?.font = UIFont.systemFontOfSize(14)

        return button
        
    }()
    
    ///评论按钮
    private lazy var commentButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        
        button.setTitle("评论", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        
        // 注意: 修改按钮的字体的话 titleLabel
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        return button
        
    }()
    
    ///评论按钮
//    private lazy var goodButton: UIButton = {
//        
//        let button = UIButton(type: UIButtonType.Custom)
//        
//        button.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Normal)
//        
//        button.setTitle("点赞", forState: UIControlState.Normal)
//        
//        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
//        
//        // 注意: 修改按钮的字体的话 titleLabel
//        button.titleLabel?.font = UIFont.systemFontOfSize(14)
//        
//        return button
//        
//    }()
    
    private lazy var goodButton: UIButton = UIFactory.getButton("点赞", textColor: nil, image: "timeline_icon_like", bgImage: nil, target: self, action: "")
}
